def prostoe(n):
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

d = {
    "zero": 0,
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9,
}

a = input().split()
if len(a) != 3 or (i != a for i in d) or a[0] == 'zero':
    print('Wrong input')
else:
    k = 0
    for i in a:
        k *= 10
        k += d[i]
    num1 = k + 1
    num2 = k - 1

    for i in range(100):
        num1 -= 1
        num2 += 1
        if prostoe(num1):
            print(num1)
            break
        elif prostoe(num2):
            print(num2)
            break